package com.monitor.controller.back;

import com.alibaba.fastjson.JSON;
import com.monitor.common.response.ResponseFactory;
import com.monitor.controller.BaseController;
import com.monitor.service.MonitorService;
import com.monitor.vo.MonitorEditReq;
import com.monitor.vo.MonitorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;

/**
 * @ClassName MonitorController
 * @Package com.monitor.controller.back
 * @Description TODO
 * @Author zhixingbai
 * @Create 2018/10/1116:41
 */
@RestController
@RequestMapping("/back/monitor")
public class MonitorController extends BaseController {
    @Autowired
    private MonitorService monitorService;

    @RequestMapping(value="/list",method = RequestMethod.POST)
    public Object list(MonitorVo monitorVo){
        return monitorService.selectMonitorList(monitorVo);
    }


    @RequestMapping(value="/bakList",method = RequestMethod.POST)
    public Object bakList(MonitorVo warningVo){
        return monitorService.selectBakList(warningVo);
    }

    @RequestMapping(value = "/bakDel",method = RequestMethod.POST)
    public Object delBak(@RequestParam("delDate")Integer delDate){
        logger.info("删除备份数据：{}天以前的数据",delDate);
        return monitorService.delBak(delDate);
    }

    @RequestMapping(value = "/setCostTime",method = RequestMethod.POST)
    public Object setCostTime(MonitorEditReq editReq){
        logger.info("修改报警时间间隔:{}", JSON.toJSONString(editReq));
        return monitorService.setCostTime(editReq);
    }

    @RequestMapping(value = "/setTypeTime",method = RequestMethod.POST)
    public Object setTypeTime(MonitorEditReq editReq){
        logger.info("修改基于类型报警时间间隔:{}", JSON.toJSONString(editReq));
        return monitorService.setTypeTime(editReq);
    }

    @RequestMapping("/del/{id}")
    public Object del(@PathVariable("id")Integer id){
        logger.info("删除账号：{}",id);
        return monitorService.delMonitor(id);
    }

    @RequestMapping(value = "/editWarning",method = RequestMethod.POST)
    public Object editWarning(@RequestParam("id") Integer id,@RequestParam("isWarning") String isWarning){
        logger.info("更新账号是否报警，编号：{},isWarning:{}",id,isWarning);
        return monitorService.editWarning(id,isWarning);
    }



}
